import 'package:flutter/material.dart';
import 'package:hello_world/route-view-i.dart';
import 'package:hello_world/bus.dart';

class LayoutI extends StatefulWidget {
  @override
  _LayoutI createState() => new _LayoutI();
}

class _LayoutI extends State<LayoutI> {
  BuildContext viewContext;
  int selectedIndex = 0;
  @override
  Widget build(BuildContext context) {
    bus.emit("set_context", context);
    return Scaffold(
      body: RouteViewI(),
      bottomNavigationBar: new BottomNavigationBar(
        fixedColor: Colors.black87,
        type: BottomNavigationBarType.shifting,
        iconSize: 24,
        items: <BottomNavigationBarItem>[
          new BottomNavigationBarItem(
            title: Text("首页",style: TextStyle(color: Colors.black87)),
            icon: new Icon(Icons.assessment),
            backgroundColor: Color(0xffEAEAEA),
          ),
          new BottomNavigationBarItem(
            title: Text("购物车",style: TextStyle(color: Colors.black87)),
            icon: new Icon(Icons.assessment),
            backgroundColor: Color(0xffEAEAEA)
          ),
          new BottomNavigationBarItem(
            title: Text("设置",style: TextStyle(color: Colors.black87)),
            icon: new Icon(Icons.assessment),
            backgroundColor: Color(0xffEAEAEA)
          ),
        ],
        currentIndex: selectedIndex,
        onTap: (int index){
          setState(() {
            this.selectedIndex = index;
          });
          switch (index) {
            case 0:
              Navigator.pushNamed(this.viewContext, '/home');
              break;
            case 1:
              Navigator.pushNamed(this.viewContext, '/cart');
              break;
            case 2:
              Navigator.pushNamed(this.viewContext, '/seting');
              break;
            default:
              break;
          }
        }
      ),
    );    
  }
  @override
  void initState() {
    super.initState();
    bus.on("view_context", (_context) {
      this.viewContext = _context;
    });
  }
}
